package com.googlecode.kipler.container.dl.operational;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.googlecode.kipler.container.dl.ABox;
import com.googlecode.kipler.container.dl.Individual;
import com.googlecode.kipler.container.dl.SHIQABox;


/**
 * 
 * @author İnanç Seylan
 *
 */
public class SHIQAncestorCollector implements AncestorCollector {

	private SHIQABox aBox;

	private Individual individual;

	/**
	 * @param box
	 * @param individual
	 */
	public SHIQAncestorCollector(SHIQABox box, Individual individual) {
		setABox(box);
		setIndividual(individual);
	}

	public List<Individual> collect() {
		List<Individual> result = new ArrayList<Individual>();
		if (!aBox.isRoot(individual)) {
			boolean finished = false;
			Individual currIndv = individual;
			do {
				Iterator<Individual> i = aBox.predecessorIterator(currIndv);
				if (i.hasNext()) {
					currIndv = i.next();
					if (!aBox.isRoot(currIndv)) {
						result.add(currIndv);
					} else {
						finished = true;
					}
				} else {
					finished = true;
				}
			} while (!finished);
		}
		return result;
	}

	public SHIQABox getABox() {
		return aBox;
	}

	public Individual getIndividual() {
		return individual;
	}

	public void setABox(ABox box) {
		this.aBox = (SHIQABox) box;
	}

	public void setIndividual(Individual individual) {
		this.individual = individual;
	}

}
